<?php
#+------------------------------------------------------------------
#| 普通的。
#+------------------------------------------------------------------
#| Author:Janmas Cromwell <janmas-cromwell@outlook.com>
#+------------------------------------------------------------------
namespace form\element\form;

class Checkbox extends Column
{

    protected $options = [];

    protected $check;

    protected $color = '';

    public function options(array $options = [], $chekced = '')
    {
        $this->options = $options;
        $this->check = $chekced;
        return $this;
    }

    public function color(string $color = '')
    {
        $this->color = $color;
        return $this;
    }

    /**
     * @inheritDoc
     */
    protected function normal()
    {
        $label = $this->getLabel();
        $id = $this->getId();
        $class = $this->getClass();
        $disabled = $this->getDisabled();
        $radio = '';
        $i = 0;
        foreach ($this->options as $value => $title) {
            $chekced = '';
            if ($value == $this->check) {
                $chekced = ' checked';
            }
            $radio .= '<div class="custom-control custom-checkbox ' . $this->color . ' ">
								<input class="custom-control-input" type="checkbox" name="' . $this->name . '" id="' . $id . $i . '" value="' . $value . '"  ' . $chekced . ' ' . $disabled . '>
								 <label class="custom-control-label" for="' . $id . $i . '">' . $title . '</label>
						</div>';
            ++$i;
        }
        return <<<HTML
<div class="form-group $class">
<label for="$id" class="">$label</label>
$radio
</div>
HTML;
    }

    /**
     * @inheritDoc
     */
    protected function group()
    {
        // TODO: Implement group() method.
    }

    /**
     * @inheritDoc
     */
    protected function grid()
    {
        // TODO: Implement grid() method.
    }

    /**
     * @inheritDoc
     */
    protected function table()
    {
        // TODO: Implement table() method.
    }

    /**
     * @inheritDoc
     */
    protected function vertical()
    {
        // TODO: Implement vertical() method.
    }

    /**
     * @inheritDoc
     */
    protected function inline()
    {
        $label = $this->getLabel();
        $id = $this->getId();
        $class = $this->getClass();
        $disabled = $this->getDisabled();
        $radio = '';
        $i = 0;
        foreach ($this->options as $value => $title) {
            $chekced = '';
            if ($value == $this->check) {
                $chekced = ' checked';
            }
            $radio .= '<div class="custom-control custom-checkbox custom-control-inline ' . $this->color . ' ">
								<input class="custom-control-input" type="checkbox" name="' . $this->name . '" id="' . $id . $i . '" value="' . $value . '"  ' . $chekced . ' ' . $disabled . '>
								 <label class="custom-control-label" for="' . $id . $i . '">' . $title . '</label>
						</div>';
            ++$i;
        }
        return <<<HTML
<div class="form-group $class">
<label for="$id" class="">$label</label>
$radio
</div>
HTML;
    }
}